﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DatabaseTools;

namespace DatabaseUpdate
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Config.Get.ConnectionString = textBox1.Text;
            Data dt = new Data((byte)comboBox1.SelectedIndex);
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Şema Dosyası|*.bin";
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                dt.CreateSchema(dlg.FileName);
                MessageBox.Show("Tamamlandı !");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Config.Get.ConnectionString = textBox1.Text;
            Data dt = new Data((byte)comboBox1.SelectedIndex);
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Şema Dosyası|*.bin";
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                dt.UpdateDb(dlg.FileName);
                MessageBox.Show("Tamamlandı !");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 0;
            textBox1.Text = "Data Source=TFSSERVER;Database=TEST;user id=sa";
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                textBox2.Enabled = false;
                button3.Enabled = false;
            }
            else
            {
                textBox2.Enabled = true;
                button3.Enabled = true;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Sql Ce|*.sdf";
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox2.Text = dlg.FileName;
                textBox1.Text = "Data Source=" + dlg.FileName;
            }
        }
    }
}
